/**
 * D5Power Studio FPower 2D MMORPG Engine
 * 第五动力FPower 2D 多人在线角色扮演类网页游戏引擎
 * 
 * copyright [c] 2010 by D5Power.com Allrights Reserved.
 */
package com.D5Power.Render
{
	import com.D5Power.Objects.CharacterObject;
	import com.D5Power.Objects.GameObject;
	
	import flash.geom.Point;
	import flash.geom.Rectangle;

	/**
	 * 角色渲染器
	 */ 
	public class RenderCharacter extends RenderAllCharacter
	{
		/**
		 * 是否镜像
		 */ 
		private var ismirror:Boolean = false;
		
		public function RenderCharacter()
		{
			super();
		}
		
		override public function render(o:GameObject):void
		{
			var c:CharacterObject = o as CharacterObject;
			
			var targetx:Number;
			var targety:Number;
			var maxX:uint = c.controler.perception.Scene.Map.maxX;
			var maxY:uint = c.controler.perception.Scene.Map.maxY;
			if(o.beFllow)
			{
				targetx = c.Pos.x<Global.W/2 ? c.Pos.x : Global.W/2;
				targety = c.Pos.y<Global.H/2 ? c.Pos.y : Global.H/2;
				
				targetx = c.Pos.x>maxX-Global.W/2 ? c.Pos.x-(maxX-Global.W) : targetx;
				targety = c.Pos.y>maxY-Global.H/2 ? c.Pos.y-(maxY-Global.H) : targety;
				// 摄像机跟随目标，除非超出地图范围，否则一直位于地图中心
				
			}else{
				targetx = c.Pos.x;
				targety = c.Pos.y;
			}
			var p:Point = new Point(int(targetx-c.graphics.frameWidth/2),int(targety-c.graphics.frameHeight+c.renderY));
			
			renderShadow(c,p);
			if(c.directionNum>=0)
			{
				draw(c.graphics.bitmap,c.renderRect,p);
			}else{
				draw(c.graphics.mirrorBitmapData,c.renderRect,p);
			}
			showname(c,p);
			renderStuff(c,p);
			
			super.render(o);
		}
	}
}